/*
https://www.rustfinity.com/practice/rust/challenges/aor-2024-7/description

*/

pub struct LogQuery<'a> {
    logs: &'a Vec<String>,
}

// 1. Finish the implementation of LogQuery
impl<'a> LogQuery<'a> {
    // 2. Create a public associated function named `new()` that will take a reference to a vector of strings
    //
    // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and
    //    returns a vector of references to those logs.

    pub fn new(logs: &'a Vec<String>) -> Self {
        LogQuery { logs }
    }
    // pub fn new(logs: &Vec<String>) -> LogQuery {
    //     LogQuery { logs: &logs }
    // }

    pub fn search(&self, keyword: &str) -> Vec<&'a String> {
        self.logs
            .iter()
            .filter(|l| l.contains(keyword))
            .collect::<Vec<&String>>()
    }
    // pub fn search2(&self, keyword: &str) -> Vec<&String> {
    //     self.logs.iter().filter(|x| x.contains(keyword)).collect()
    // }
}

/*

pub struct LogQuery<'a> {
    logs: &'a Vec<String>,
}
// 1. Finish the implementation of LogQuery
impl<'a> LogQuery<'_> {
    // 2. Create a public associated function named `new()` that will take a reference to a vector of strings
    pub fn new(logs: &Vec<String>) -> LogQuery {
        LogQuery { logs: &logs }
    }
    // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and
    //    returns a vector of references to those logs.
    pub fn search(&self, keyword: &str) -> Vec<&String> {
        self.logs.iter().filter(|x| x.contains(keyword)).collect()
    }
}

*/
